package com.blue.ocean.hole.async;

import com.alibaba.fastjson.JSONObject;
import java.util.Date;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public class AsyncService {

    @Async(value = "async1")
    public void execute(Job job)  {
        System.out.println("任务开始执行,当前时间为"+new Date());
        System.out.println(Thread.currentThread().getName());

        try {
            Thread.sleep(3000L);
            System.out.println(JSONObject.toJSON(job));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("任务已执行完,当前时间为"+new Date());
    }

    @Async(value = "async2")
    public void execute2(Job job)  {
        System.out.println("任务开始执行,当前时间为"+new Date());
        System.out.println(Thread.currentThread().getName());

        try {
            Thread.sleep(3000L);
            System.out.println(JSONObject.toJSON(job));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("任务已执行完,当前时间为"+new Date());
    }
}
